package com.ruoyi.communitys.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.communitys.domain.CommunityContent;
import com.ruoyi.communitys.service.CommunityContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.communitys.mapper.CommunityMapper;
import com.ruoyi.communitys.domain.Community;
import com.ruoyi.communitys.service.ICommunityService;

/**
 * 论坛Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-25
 */
@Service
public class CommunityServiceImpl implements ICommunityService 
{
    @Autowired
    private CommunityMapper communityMapper;
    @Autowired
    private CommunityContentService communityContentService;

    /**
     * 查询论坛
     * 
     * @param id 论坛主键
     * @return 论坛
     */
    @Override
    public Community selectCommunityById(Long id)
    {
        return communityMapper.selectCommunityById(id);
    }

    /**
     * 查询论坛列表
     * 
     * @param community 论坛
     * @return 论坛
     */
    @Override
    public List<Community> selectCommunityList(Community community)
    {
        return communityMapper.selectCommunityList(community);
    }

    /**
     * 新增论坛
     * 
     * @param community 论坛
     * @return 结果
     */
    @Override
    public int insertCommunity(Community community)
    {
        CommunityContent communityContent = new CommunityContent();
        community.setCreateTime(DateUtils.getNowDate());
        communityMapper.insertCommunity(community);
        List<Community> communities = communityMapper.selectCommunityList(null);
        communityContent.setContent(community.getContent());
        communityContent.setId(communities.get(communities.size()-1).getId().toString());
        communityContentService.addContent(communityContent);
        return 1;
    }

    /**
     * 修改论坛
     * 
     * @param community 论坛
     * @return 结果
     */
    @Override
    public int updateCommunity(Community community)
    {
        return communityMapper.updateCommunity(community);
    }

    /**
     * 批量删除论坛
     * 
     * @param ids 需要删除的论坛主键
     * @return 结果
     */
    @Override
    public int deleteCommunityByIds(Long[] ids)
    {
        return communityMapper.deleteCommunityByIds(ids);
    }

    /**
     * 删除论坛信息
     * 
     * @param id 论坛主键
     * @return 结果
     */
    @Override
    public int deleteCommunityById(Long id)
    {
        return communityMapper.deleteCommunityById(id);
    }

    @Override
    public List<Community> selectCommunityAndUserList(String title) {
        return communityMapper.selectCommunityAndUserList(title);
    }
}
